package com.dhh.sky.activity;

import com.dhh.sky.R;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class MenuFragment extends ListFragment {

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		setListAdapter(new NavigateAdapter(
				getActivity(),
				android.R.layout.simple_list_item_1, 
				new String[] {getString(R.string.navigate_file), getString(R.string.navigate_document), getString(R.string.navigate_photo), getString(R.string.navigate_download), getString(R.string.navigate_camera),getString(R.string.navigate_logout)}));
		getListView().setCacheColorHint(0);
		getListView().setDivider( null );
		getListView().setDividerHeight(0); 
		getListView().setBackgroundColor(Color.rgb(238, 242, 245));
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		((MenuActivity)getActivity()).getSlideoutHelper().close();
		Intent intent = new Intent(getActivity(),FileListActivity.class);
		if(position==1){			
			intent.putExtra("filter", FileListActivity.FILTER_DOCUMENT);  //document
		}else if(position==2){
			intent.putExtra("filter", FileListActivity.FILTER_PHOTOS); //photos		
		}else if(position==3){
			intent = new Intent(getActivity(),FileViewActivity.class);		
		}else if(position==4){
			intent = new Intent(getActivity(),CameraUploadActivity.class);		
		}else if(position==5){
			((MenuActivity)getActivity()).logout();	
			return;
		}
    	startActivity(intent);
	}
	
	class NavigateAdapter extends ArrayAdapter<String> {
		private Context context;
		private String[] values;
		
		public NavigateAdapter(Context context, int textViewResourceId,String[] values) {
			super(context, R.layout.navigate_item, values);
			this.context = context;
			this.values = values;
		}
		
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			View rowView = inflater.inflate(R.layout.navigate_item, parent, false);
			TextView title = (TextView) rowView.findViewById(R.id.fng_title);
			Button icon = (Button) rowView.findViewById(R.id.fng_icon);
			
			if(position==0){
				icon.setBackgroundResource(R.drawable.ic_all_files);
			}else if(position==1){
				icon.setBackgroundResource(R.drawable.ic_folder);
			}else if(position==2){
				icon.setBackgroundResource(R.drawable.ic_album);
			}else if(position==3){
				icon.setBackgroundResource(R.drawable.ic_download_save);
			}else if(position==4){
				icon.setBackgroundResource(R.drawable.ic_camera);
			}else if(position==5){
				icon.setBackgroundResource(R.drawable.ic_logout);
			}
			title.setText(values[position]);

			return rowView;
		}
		
	}
	
}

	
